package com.bzy.blade_auth.service.impl;

import com.baomidou.mybatisplus.extension.api.R;
import com.bzy.blade_auth.mapper.JurisdictionMapper;
import com.bzy.blade_auth.service.JurisdictionService;
import com.bzy.bladeauthapi.entry.Jurisdiction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JurisdictionServiceImpl implements JurisdictionService {


    private final String error = "服务器异常";
    private final String success = "success";

    @Autowired
    private JurisdictionMapper jurisdictionMapper;

    @Override
    public R add(Jurisdiction jurisdiction) {
        try {
            jurisdictionMapper.add(jurisdiction);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed("服务器异常");
        }
        return R.ok(success);
    }

    /**
     * 修改角色的权限、在修改角色权限的时候、需要去进行判断当前的权限的数据信息、
     * 是否被其他的角色所拥有、如果其他的角色纯在当前的权限信息的话、不可以修改当前的权限的数据信息;
     * @param jurisdiction
     * @return
     */
    @Override
    public R uodate(Jurisdiction jurisdiction) {
        try {
            jurisdictionMapper.update(jurisdiction);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed("服务器异常");
        }
        return R.ok(success);
    }

    @Override
    public R delete(Jurisdiction jurisdiction) {
        try {
            jurisdictionMapper.delete(jurisdiction);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed("服务器异常");
        }
        return R.ok(success);
    }

    @Override
    public R selOne(Jurisdiction jurisdiction) {

        Jurisdiction jurisdiction1 = jurisdictionMapper.selOne(jurisdiction);
        return jurisdiction1==null?R.failed(error):R.ok(jurisdiction1);
    }

    @Override
    public R selList(Jurisdiction jurisdiction) {
        List<Jurisdiction> jurisdictions = jurisdictionMapper.selList(jurisdiction);
        return jurisdictions==null?R.failed(error):R.ok(jurisdictions);
    }
}
